package com.tomek.ktoryoperator.utils;

import android.content.Context;
import android.content.pm.PackageManager;
import android.telephony.TelephonyManager;

public class TelephonyUtils {
	public static final String PL_COUNTRY_PREFIX = "48";
	private static final String PLUS = "+";

	public static String getCountryPrefix(Context context) {
		TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

		String iso = tm.getNetworkCountryIso();
		return iso;
	}

	public static String cleanNumber(String number) {
		if (number.startsWith(PLUS)) {
			number = number.substring(1);
		}

		if (number.length() == 9) {
			return PL_COUNTRY_PREFIX + number;
		}

		return number;
	}

	public static String trimLeadingPlus(String number) {
		if (number.startsWith("+")) {
			return number.substring(1);
		} else {
			return number;
		}
	}

	public static boolean isCapableWithTelephony(Context context) {
		return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
	}
}
